//
//  UIBarButtonItem+extention.swift
//  网易新闻项目
//
//  Created by 薄文飞 on 16/3/3.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageName: String? = nil, titel: String? = nil ,target: AnyObject?, action: Selector) {
        
        self.init()
        
        let button = UIButton()

        //添加点击事件
        button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let t = titel {
        
            button.setTitle(t, forState: .Normal)
                button.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
            
            button.setTitleColor(UIColor(colorLiteralRed: 52/255, green: 52/255, blue: 52/255, alpha: 1), forState: .Normal)
            button.titleLabel?.font = UIFont.boldSystemFontOfSize(14)
        }
        
        if  let name = imageName {
            
        button.setImage(UIImage(named: name), forState: .Normal)
        button.setImage(UIImage(named: "\(name)_highlighted"), forState: .Highlighted)
            
             }
        button.sizeToFit()
        
        self.customView = button
        
       
    }
}